package com.PopUps;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.Animations.AnimUtil;
import com.TextFormat.UtilFonts;
import com.shareup.R;


public class PopUpClass {

    private Context context;

    public PopUpClass(Context context) {

        super();
        this.context = context;
    }

    public void hideLoadingList(ViewGroup container) {

        AnimUtil.animatePopUp(container, false, null);
    }

    public void setLoadingList(ViewGroup container) {

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflater.inflate(R.layout.item_loading, null);

        TextView txt = (TextView) v.findViewById(R.id.item_loading_text);
        UtilFonts.setTextRegularFont(txt);

        container.addView(v);

        AnimUtil.animatePopUp(container, true, null);
    }

    public void setMessage(String message, int iconResource, ViewGroup container) {

        if (container.getChildCount() == 0
                    || container.getChildAt(0).getTag() == null
                    || !container.getChildAt(0).getTag().toString().equals(message)) {
            if (container.getChildCount() > 0) {
                container.removeAllViews();
            }
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v = inflater.inflate(R.layout.information_message, null);
            TextView txt = (TextView) v.findViewById(R.id.info_message);
            ImageView icon = (ImageView) v.findViewById(R.id.info_icon);
            //
            UtilFonts.setTextRegularFont(txt);
            txt.setText(message);
            icon.setImageResource(iconResource);
            //
            v.setTag(message);
            container.addView(v);
            AnimUtil.animatePopUp(container, true, null);
        }
    }
}
